package com.tanhua.server.test;

import com.tanhua.model.db.UserInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class UserInfoCacheService {

    //根据id查询
    @Cacheable(value = "user",key = "#userId")
    public UserInfo queryById(Long userId) {
        //从数据库查询
        System.out.println("从数据库查询");
        UserInfo user = new UserInfo();
        user.setId(userId);
        user.setNickname("ceshi");
        return user;
    }

    //根据id修改
    @CacheEvict(value = "user",key = "#userId")
    public void update(Long userId) {
        UserInfo user = new UserInfo();
        user.setId(userId);
        user.setNickname("itcast");
    }
}